<template>
	<view class="content">
		<!-- 顶部描述 -->
		<view class="sub_des">
			<text class="des_txt">致力为您提供高品质、专业的平台服务,对我们的服务有任何意见都可以提出，我们将尽快回复</text>
		</view>
		<!-- 下方内容区 -->
		<view class="sub_con">
			<!-- 标签 上 -->
			<view class="con_top">
				<view class="con_top_box">
					<view class="line"> </view>
					<view class="biaotitle">您好，请选择标签</view>
				</view>
				<view class="label_list">
					<block v-for="item in labelList" :key="item.id">
						<text  v-model="type_id" class="label_item" :class="current === item.id? 'isSelectLabel' : ''" @click="btnLable(item.id)">{{item.name}}</text>
					</block> 
				</view>
			</view>
			<!-- 具体内容建议 -->
			<view class="con_deta">
				<view class="con_top_box">
					<view class="line"> </view>
					<view  class="biaotitle">具体建议内容</view>
				</view>
				<view class="message">
					<textarea maxlength="200"  class="textarea" name="content" id="" cols="30" rows="10" placeholder="在这里输入内容字数不超过200字" v-model="content"> </textarea>
				</view>
			</view>
			<!-- 上传图片 -->
			<view class="add-img-box" v-if="false">
				<view class="add-img-item" v-for="(item, index) in imgList" :key="index">
					<image class="add-img" @click="imgInfo(index)" :src="item" mode="aspectFill"></image>
					<image  class="add-img-del" @click="delImg(index)" :src="imgUrl+'/static/wap/infoImg/delete.png'"></image>
				</view>
				<!-- 上传按钮， 图片少于3张展示 -->
				<view v-if="imgList.length < 3 " class="add-img-item" @click="uploadImg">
					<image class="add-img" :src="imgUrl+'/static/wap/infoImg/shangtu@2x.png'"></image>
				</view>
				<text class="rem_img">{{imgList.length}}/3</text>
			</view>
			<!-- 提交按钮 -->
			<view class="main_sub">
				<view class="left_sub"   @click="toFeebackList">
					查看记录
				</view>
				<view class="right_sub"  @click="setFeeback">
					提交反馈
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import util from '../../static/util.js'
	export default {
		data() {
			return {
				imgUrl:util.globalData.imgPre,
				// 标签列表
				labelList:'',
				// 当前选中
				current: 2,
				localImg:[],
				imgList: [],
				cloudimgList: [],
				imgCount: 3,//最多支持3张上传 
				content:'',
				type_id:'',
			};
		},
		onLoad(){
			this.getFeebackType();//获取意见反馈类型
		},
		methods:{
			uploadImg(){
				var that=this;
					uni.chooseImage({
					count: 3, //默认9
					sourceType:['album','camera'],
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					success: (res) =>{
						console.log(JSON.stringify(res.tempFilePaths));
						this.localImg=res.tempFilePaths
						this.upload(this.localImg,this.localImg.length-1,0)
					},
					fail(res){
					console.log(res);	
					}
				});
			},
			upload(arr,limit,n){
				if(n>limit){
					uni.showToast({
							title:'上传成功'
						});
					console.log(this.imgList)	
					return
				}
				console.log('调用了'+n+'次')
				console.log(arr[n])
				this.$upload({
					path:arr[n],
					success:(res2)=>{
						if(typeof res2== 'string'){
							res2=JSON.parse(res2)
						}
						if(res2.code!=200){
							uni.showToast({
								title:res2.msg,
								icon:"none"
							})
							this.imgList=[]
							return
						}
			
						this.imgList.push(res2.data.all_path)
						n++
						this.upload(this.localImg,this.localImg.length-1,n)
						//保存头像
					},
					fail:function fail(res2){
						console.log(res2)
						uni.showToast({
								title:'请稍后再试',
								icon:'none'
							});
					},
					complete:function complete(){
						console.log(111)
					}
				})
			},
			setFeeback(){
				var that=this;
				that.ajax({
					url:'/api/feedback/setFeeback',
					data:{
						type_id:that.type_id,
						content:that.content,
						is_first:1
					},
					success:function(res){
						console.log(res);
						if(res.code !=200){
							uni.showToast({
								title:res.msg,
								icon:'none'
							})
							return
						}
						uni.showToast({
							title:"发布成功",
							icon:'none'
						});
						setTimeout(() => {
							uni.navigateTo({
								url: "feedbackList"
							})
						}, 1000)
					}
				  })
			},
			getFeebackType(){
				var that=this;
				that.ajax({
					url:'/api/feedback/getFeebackType',
					success:function(res){
						that.labelList=res.data;
						that.current=that.labelList[0].id
						that.type_id=that.current
					}
				  })
			},
			toFeebackList(){
				uni.navigateTo({
					url: "feedbackList"
				})
			},
			btnLable(id){
				console.log(id)
				this.current = id 
				this.type_id=id 
			}, 
			// 查看大图
			imgInfo(i) {
				let tempList = [];
				this.imgList.forEach(img => {
					tempList.push(img.path);
				}); 
				//显示图片
				uni.previewImage({
					current: i, 
					loop: false,	// 是否循环
					urls: tempList, // 需要预览的图片链接列表
					indicator: 'default' // 图片指示器样式 
				});
			},
			// 删除图片
			delImg(i) { 
				// 弹框
				uni.showModal({
					content: '确定删除这张吗？',
					success: res => { 
						if (res.confirm) {
							this.imgList.splice(i, 1);
							this.imgCount++;
						}  
					}
				});
			},
			// 点击上传
			openCamera() {  
				uni.chooseImage({
					// 从相册选择图片
					sourceType:['album'],
					// 默认张数
					count: this.imgCount,
					// 可以指定是原图还是压缩图，默认二者都有
					sizeType: ['compressed'],
					
					success: e => { 
						// tempFiles 图片的本地文件列表 
						this.imgList = [...this.imgList, ...e.tempFiles];   
						// 减去已上传的张数
						this.imgCount = 3 - this.imgList.length; 
					}
				});
			},
			// 提交按钮
			// submit(e) {
			// 	this.submitData = null;
			// 	if (this.imgList.length < 1) {
			// 		uni.showToast({
			// 			title: '请添加图片',
			// 			icon: 'none'
			// 		});
			// 		return false;
			// 	}
			// 	uni.showLoading({
			// 		title: '上传图片',
			// 		mask: false
			// 	});
			// 	for (let i = 0; i < this.imgList.length; i++) {
			// 		console.log("test！"+this.imgList[i].path);			
			// 		this.$cloud.uploadFile({
			// 			filePath: this.imgList[i].path,
			// 			success: (res) => {
			// 				//保存图片的路径
			// 				this.cloudimgList.push(res.fileID);
			// 			},
			// 			fail: (err) => {
			// 				console.log(err);
			// 			},
			// 			complete: () => {
			// 				//uni.hideLoading();
			// 				if (this.cloudimgList.length == this.imgList.length) {
			// 					uni.hideLoading();
			// 					uni.showToast({
			// 						title: '全部上传成功！',
			// 						icon: 'none'
			// 					});
			// 				}
			// 			}
			// 		})
			// 		}
			// }, 
		}, 
	}
</script>

<style lang="less" scoped>
	.biaotitle{
		font-size:28rpx;
	}
	.sub_des{
		margin: 40rpx 50rpx; 
		line-height: 32rpx; 
		text-indent: 1em; 
		.des_txt {
			font-size: 28rpx;
			color: #616161; 
		}
	}
	
	.sub_con{
		position: relative;
		margin: 0 30rpx;  
		.con_top{
			font-size: 32rpx;
			color: #616161;
			height: 300rpx; 


			.label_list{ 
				margin-top: 20rpx;
				padding: 20rpx 0;
				.label_item{
					display: inline-block; 
					margin: 0 20rpx 30rpx 0;
					width: 210rpx;
					height: 64rpx;
					line-height: 64rpx;
					text-align: center;
					font-size: 28rpx;
					border-radius: 32rpx;
					background-color: #F3F3F5;
				}
			}
		}
		.con_deta{
			font-size: 32rpx;
			color: #616161;  

			.message{ 
				margin-top: 28rpx;
				height: 358rpx; 
				.textarea{  
					width: calc(100% - 50rpx);
					height: calc(100% - 50rpx);
					padding: 25rpx;
					background-color: #F3F3F5;
					border-radius: 15rpx;
				}
			}
		}
		.sub_btn{
			margin-top: 106rpx;
			height: 90rpx;
			line-height: 90rpx;
			text-align: center;
			font-size: 36rpx;
			color: #fff;
			background-color: #2AABAD;
			border-radius: 45rpx;
		}
	}
	
	.add-img-box {
		position: absolute;
		bottom: 220rpx;
		display: flex; 
		height: 100rpx;
		padding-left: 10rpx;
		flex-direction: row;
		flex-wrap: wrap;
	}
	.add-img-item { 
		// width: 100rpx;
		height: 100rpx;
		border-radius: 24rpx;
		position: relative;
		padding: 9rpx 0;
		margin-left: 20rpx;
		z-index: 100;
	}
	.add-img-camera {
		flex: 1;
	}
	.add-img {
		width: 100rpx;
		height: 100rpx;
		border-radius: 24rpx;
	}
	.add-img-del {
		position: absolute;
		width: 24rpx;
		height: 24rpx;
		right: 8rpx;
		top: 17rpx; 
		border-radius: 20rpx;
	}
	.address-time {
		width: 484rpx;
		height: 88rpx;
		background-color: rgba(245, 245, 245, 1);
		opacity: 1;
		border-radius: 24rpx;
		text-align: center;
	
		font-size: 35rpx;
		font-weight: 500;
		color: rgba(51, 51, 51, 1);
	}
	.line{
		width: 750rpx;
		height: 1px;
		transform: scaleY(0.3);
		background-color: rgba(0,0,0,0.5);
	}
	.rem_img{
		padding: 64rpx 0 0 40rpx;
		font-size: 30rpx;
		color: #9E9EA0;
	}
	.main_sub{
		margin-top: 106rpx;
		height: 90rpx;
		line-height: 90rpx;
		
	}
	.left_sub{
		text-align: center;
		font-size: 32rpx;
		color: #fff;
		background-color: #999;
		border-radius: 45rpx;
		height: 90rpx;
		line-height: 90rpx;
		width:300rpx;
		float:left;
	}
	.right_sub{
		text-align: center;
		font-size: 32rpx;
		color: #fff;
		background-color: #2AABAD;
		border-radius: 45rpx;
		height: 90rpx;
		line-height: 90rpx;
		width:300rpx;
		float:right;
	}
	.con_top_box{
		display: flex;
		align-items: center;
		justify-content: flex-start;
		height:20rpx;
		.line{
			margin-right: 18rpx;
			width: 8rpx;
			height: 100rpx;
			background: #ff9000;
			border-radius: 4rpx;
		}
		
	}
</style>
